home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume20 / xxalloc < prev    next >
Encoding:
Internet Message Format  |  1989-10-16  |  51.7 KB

  1. Subject:  v20i028:  Multi-dimension dynamic array manipulation package
  2. Newsgroups: comp.sources.unix,comp.lang.c
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5. Followups-to: comp.sources.d
  6.  
  7. Submitted-by: Harold G. Walters <walters@ce.okstate.edu>
  8. Posting-number: Volume 20, Issue 28
  9. Archive-name: xxalloc
  10.  
  11. [  109 functions!?  Wow... This is one of the rare cross-posts into
  12.    comp.lang.c /r$  ]
  13.  
  14. xxalloc is a family of routines for dynamic array manipulation in one,
  15. two and three dimensions.  Routines are included for allocation,
  16. initialization, printing, renumbering, and freeing both arrays of
  17. structures and arrays of simple types.  Since the "edge-vector" approach
  18. is used for two and three dimensional arrays, this set of routines
  19. allows for the development of reusable subroutine libraries without
  20. regard to some "maximum" dimension.  Both positive and negative indices
  21. are allowed. 
  22.  
  23. Installation instructions are in the makefile.  A test program is
  24. included to exercise most of the package.  I have compiled this package
  25. on many machines (SYS5, BSD, MSDOS) without a hitch.  The man page uses
  26. some abbreviation to save space since there are actually 109 functions
  27.  
  28.  
  29. --
  30. Harold G. Walters                 Internet: walters@ce.okstate.edu
  31. School of Civil Engineering       Uucp: {cbosgd, ihnp4, uiucdcs}
  32. Oklahoma State University                   !okstate!osubem!walters
  33. Stillwater, OK 74078 "If all you have is a hammer, everything looks like a nail"
  34.  
  35. #! /bin/sh
  36. # This is a shell archive.  Remove anything before this line, then unpack
  37. # it by saving it into a file and typing "sh file".  To overwrite existing
  38. # files, type "sh file -c".  You can also feed this as standard input via
  39. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  40. # will see the following message at the end:
  41. #        "End of archive 1 (of 1)."
  42. # Contents:  MANIFEST Makefile README example1.c example2.c nx.c nx.h
  43. #   nxtest.c proto.h tx.c tx.h txtest.c xx.sh xxalloc.man xxerror.c
  44. #   xxh.sh xxtest.sh
  45. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  46. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  47.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  48. else
  49. echo shar: Extracting \"'MANIFEST'\" \(641 characters\)
  50. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  51. X   File Name        Archive #    Description
  52. X-----------------------------------------------------------
  53. X MANIFEST                   1    This shipping list
  54. X Makefile                   1    
  55. X README                     1    
  56. X example1.c                 1    
  57. X example2.c                 1    
  58. X nx.c                       1    
  59. X nx.h                       1    
  60. X nxtest.c                   1    
  61. X proto.h                    1    
  62. X tx.c                       1    
  63. X tx.h                       1    
  64. X txtest.c                   1    
  65. X xx.sh                      1    
  66. X xxalloc.man                1    
  67. X xxerror.c                  1    
  68. X xxh.sh                     1    
  69. X xxtest.sh                  1    
  70. END_OF_FILE
  71. if test 641 -ne `wc -c <'MANIFEST'`; then
  72.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  73. fi
  74. # end of 'MANIFEST'
  75. fi
  76. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  77.   echo shar: Will not clobber existing file \"'Makefile'\"
  78. else
  79. echo shar: Extracting \"'Makefile'\" \(2980 characters\)
  80. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  81. X#/*makefile***************************************************************/     
  82. X#/*                                    */
  83. X#/*                xxalloc                 */
  84. X#/*                                    */
  85. X#/*            Placed in the public domain            */
  86. X#/*             by Harold G. Walters 1988            */
  87. X#/*                                    */
  88. X#/*    Bug fixes, ect to walters@ce.okstate.edu until May 1989        */
  89. X#/*                                    */
  90. X#/*    This software is provided as is.  No claims are made for    */
  91. X#/*    this software regarding its fitness and/or correctness for    */
  92. X#/*     any purpose.  Use of this software is at the user's own risk.    */
  93. X#/*                                    */
  94. X#/************************************************************************/
  95. X#
  96. X# Memory is allocated with calloc().  If your compiler requires that memory
  97. X# allocated with calloc() be freed with cfree() then add a -Dfree=cfree to
  98. X# the CFLAGS line
  99. X#
  100. X# The package testing program is automatically executed.  Some compilers
  101. X# may generate warnings about illegal pointer combinations.  Ignore these -
  102. X# the compiler is wrong.  The testing program will generate a messages like
  103. X#         checking type n
  104. X# This is correct. Other messages mean something is wrong.
  105. X#
  106. X# This package should be compiled first on a UN*X machine to generate the
  107. X# .c and .h files since the Makefile uses things like sed, cp, and echo.
  108. X# The generated files can then be copied to whatever machine you want.
  109. X
  110. CFLAGS = -O
  111. X
  112. X# For installation the following need to be defined for your system
  113. X
  114. LIB = /usr/lib
  115. MAN = /usr/man/manl
  116. INCLUDE = /usr/include
  117. SECTION = l
  118. X
  119. all: xxalloc.c xxalloc.h \
  120. xxalloc.o libxxalloc.a \
  121. xxerror.o libxxerror.a \
  122. xxalloc.$(SECTION) xxtest 
  123. X
  124. xxalloc.c: nx.c tx.c 
  125. X    chmod u+x xx.sh
  126. X    cp nx.c $@
  127. X    xx.sh char c tx.c $@
  128. X    xx.sh short s tx.c $@
  129. X    xx.sh long l tx.c $@
  130. X    xx.sh int i tx.c $@
  131. X    xx.sh float f tx.c $@
  132. X    xx.sh double d tx.c $@
  133. X    
  134. xxalloc.h: nx.h tx.h 
  135. X    chmod u+x xx.sh
  136. X    cp nx.h $@
  137. X    xx.sh char c tx.h $@
  138. X    xx.sh short s tx.h $@
  139. X    xx.sh long l tx.h $@
  140. X    xx.sh int i tx.h $@
  141. X    xx.sh float f tx.h $@
  142. X    xx.sh double d tx.h $@
  143. X
  144. xxtest.c: nxtest.c txtest.c 
  145. X    chmod u+x xxtest.sh
  146. X    cp nxtest.c $@
  147. X    xxtest.sh char c d txtest.c $@
  148. X    xxtest.sh short s d txtest.c $@
  149. X    xxtest.sh long l ld txtest.c $@
  150. X    xxtest.sh int i d txtest.c $@
  151. X    xxtest.sh float f f txtest.c $@
  152. X    xxtest.sh double d lf txtest.c $@
  153. X    echo 'exit(0); }' >> $@
  154. X
  155. xxalloc.o: xxalloc.c xxalloc.h
  156. X
  157. xxtest.o: xxtest.c xxalloc.h
  158. X
  159. xxtest: xxtest.o xxalloc.h xxalloc.o xxerror.o
  160. X    $(CC) $(CFLAGS) xxtest.o xxalloc.o xxerror.o -o xxtest
  161. X    xxtest
  162. X
  163. libxxalloc.a: xxalloc.o
  164. X    ar rv $@ xxalloc.o
  165. X
  166. libxxerror.a: xxerror.o
  167. X    ar rv $@ xxerror.o
  168. X
  169. xxalloc.$(SECTION): xxalloc.man
  170. X    cp xxalloc.man xxalloc.$(SECTION)
  171. X
  172. install:
  173. X    cp libxxalloc.a $(LIB)
  174. X    chmod 664 $(LIB)/libxxalloc.a
  175. X    cp libxxerror.a $(LIB)
  176. X    chmod 664 $(LIB)/libxxalloc.a
  177. X    cp xxalloc.h $(INCLUDE)
  178. X    chmod 664 $(INCLUDE)/xxalloc.h
  179. X    cp xxalloc.$(SECTION) $(MAN)
  180. X    chmod 664 $(MAN)/xxalloc.$(SECTION)
  181. X
  182. clean:
  183. X    rm -f core *.o xxtest libxxalloc.a libxxerror.a xxalloc.$(SECTION)
  184. X
  185. superclean:
  186. X    rm -f core *.o xxtest libxxalloc.a libxxerror.a xxalloc.$(SECTION) \
  187. xxalloc.c xxalloc.h xxtest.c
  188. X
  189. X
  190. END_OF_FILE
  191. if test 2980 -ne `wc -c <'Makefile'`; then
  192.     echo shar: \"'Makefile'\" unpacked with wrong size!
  193. fi
  194. # end of 'Makefile'
  195. fi
  196. if test -f 'README' -a "${1}" != "-c" ; then 
  197.   echo shar: Will not clobber existing file \"'README'\"
  198. else
  199. echo shar: Extracting \"'README'\" \(1664 characters\)
  200. sed "s/^X//" >'README' <<'END_OF_FILE'
  201. xxalloc is a family of routines for dynamic array manipulation in one,
  202. two and three dimensions.  Routines are included for allocation,
  203. initialization, printing, renumbering, and freeing both arrays of
  204. structures and arrays of simple types.  Since the "edge-vector" approach
  205. is used for two and three dimensional arrays, this set of routines
  206. allows for the development of reusable subroutine libraries without
  207. regard to some "maximum" dimension.  Both positive and negative indices
  208. are allowed. 
  209. X
  210. When I converted to C several years ago after my first large program in
  211. XFORTRAN, the first thing I wanted to do was to have adjustable
  212. multi-dimensional arrays.  This can be achieved in C (sort of, the array
  213. dimensions are fixed) through the use of pointers (the so called
  214. X"edge-vector" approach, see also K&R p.  110).  I then added routines
  215. for manipulating structures and routines for renumbering the indices,
  216. initializing, and printing.  These routines also solve the problem of
  217. not being able to have 2D arrays greater than 64k on machines with 16
  218. bit addresses (ie.  PC's). 
  219. X
  220. Installation instructions are in the makefile.  A test program is
  221. included to exercise most of the package.  I have compiled this package
  222. on many machines (SYS5, BSD, MSDOS) without a hitch.  The man page uses
  223. some abbreviation to save space since there are actually 109 functions
  224. in this package. 
  225. X
  226. X--
  227. Harold G. Walters                 Internet: walters@ce.okstate.edu
  228. School of Civil Engineering       Uucp: {cbosgd, ihnp4, uiucdcs}
  229. Oklahoma State University                   !okstate!osubem!walters
  230. Stillwater, OK 74078 "If all you have is a hammer, everything looks like a nail"
  231. X
  232. X
  233. X
  234. X
  235. END_OF_FILE
  236. if test 1664 -ne `wc -c <'README'`; then
  237.     echo shar: \"'README'\" unpacked with wrong size!
  238. fi
  239. # end of 'README'
  240. fi
  241. if test -f 'example1.c' -a "${1}" != "-c" ; then 
  242.   echo shar: Will not clobber existing file \"'example1.c'\"
  243. else
  244. echo shar: Extracting \"'example1.c'\" \(1396 characters\)
  245. sed "s/^X//" >'example1.c' <<'END_OF_FILE'
  246. X/* example1.c */
  247. X
  248. X#include <stdio.h>
  249. X#include <xxalloc.h>
  250. X
  251. void mtxtsp(a, ib, ie, jb, je, b)
  252. double **a, **b;
  253. int ib, ie, jb, je;
  254. X{
  255. X    int i, j;
  256. X    double tmp;
  257. X    
  258. X    for (i = ib; i <= ie; i++)
  259. X         for (j = i; j <= je; j++)
  260. X        {
  261. X            tmp = a[i][j];
  262. X            b[i][j] = a[j][i];
  263. X            b[j][i] = tmp;
  264. X        }
  265. X    return;
  266. X}
  267. X
  268. main()
  269. X{
  270. X    double **a;
  271. X    int i, j;
  272. X    
  273. X/* allocate a two dimensional array of doubles */
  274. X
  275. X    a = d2_alloc(0, 9, 0, 9);
  276. X
  277. X/* initialize the array to 1.0 and print */
  278. X
  279. X    d2_init(a, 0, 9, 0, 9, 1.0);
  280. X    printf("\ninitialized to 1\n");
  281. X    d2_prnt(stdout, "%5.0f ", a, 0, 9, 0, 9);
  282. X
  283. X/* set the array equal to the 2*i + j and print*/
  284. X
  285. X    for (i = 0; i < 10; i++)
  286. X        for (j = 0; j < 10; j++)
  287. X            a[i][j] = (double) (2*i + j);
  288. X    printf("\n2*i + j\n");
  289. X    d2_prnt(stdout, "%5.0f ", a, 0, 9, 0, 9);
  290. X
  291. X/* take the transpose and print*/
  292. X
  293. X    mtxtsp(a, 0, 9, 0, 9, a);
  294. X    printf("\ntransposed\n");
  295. X    d2_prnt(stdout, "%5.0f ", a, 0, 9, 0, 9);
  296. X
  297. X/* renumber the indices a la FORTRAN and print*/
  298. X/* the new indices must be used from now on */
  299. X
  300. X    a = d2_renum(a, 0, 9, 0, 9, 1, 10, 1, 10);
  301. X    printf("\nrenumbered\n");
  302. X    d2_prnt(stdout, "%5.0f ", a, 1, 10, 1, 10);
  303. X
  304. X/* renumber the indices a la C and print */
  305. X/* the new indices must be used from now on */
  306. X
  307. X    a = d2_renum(a, 1, 10, 1, 10, 0, 9, 0, 9);
  308. X    printf("\nrenumbered again\n");
  309. X    d2_prnt(stdout, "%5.0f ", a, 0, 9, 0, 9);
  310. X
  311. X/* free the allocated memory */
  312. X
  313. X    d2_free(a, 0, 9, 0, 9);
  314. X    exit(0);
  315. X}        
  316. END_OF_FILE
  317. if test 1396 -ne `wc -c <'example1.c'`; then
  318.     echo shar: \"'example1.c'\" unpacked with wrong size!
  319. fi
  320. # end of 'example1.c'
  321. fi
  322. if test -f 'example2.c' -a "${1}" != "-c" ; then 
  323.   echo shar: Will not clobber existing file \"'example2.c'\"
  324. else
  325. echo shar: Extracting \"'example2.c'\" \(1290 characters\)
  326. sed "s/^X//" >'example2.c' <<'END_OF_FILE'
  327. X/* example2.c */
  328. X
  329. X#include <stdio.h>
  330. X#include <xxalloc.h>
  331. X
  332. typedef struct
  333. X{
  334. X    double dnum;
  335. X    int inum;
  336. X} NUM;
  337. X
  338. X/* structure initialization function */
  339. X/* passed as an argument to {d}n_init() */
  340. void num_init(num)
  341. NUM *num;
  342. X{
  343. X    num->dnum = 1.0;
  344. X    num->inum = 1;
  345. X    return;
  346. X}
  347. X
  348. X/* structure printing function */
  349. X/* passed as an argument to {d}n_prnt() */
  350. void num_prnt(fp, num)
  351. XFILE *fp;
  352. NUM *num;
  353. X{
  354. X    fprintf(fp, "%5.1f %3d ", num->dnum, num->inum);
  355. X    return;
  356. X}
  357. X
  358. main()
  359. X{
  360. X    int i;
  361. X    NUM *num;
  362. X    
  363. X/* allocate a one dimensional array of NUM */
  364. X
  365. X    num = (NUM *) n1_alloc(0, 4, sizeof(NUM));
  366. X
  367. X/* initialize the array to 1.0 and print */
  368. X
  369. X    n1_init(num, 0, 4, sizeof(NUM), num_init);
  370. X    printf("\ninitialized to 1\n");
  371. X    n1_prnt(stdout, num_prnt, num, 0, 4, sizeof(NUM));
  372. X
  373. X/* set the array equal to the i and print */
  374. X
  375. X    for (i = 0; i <= 4; i++)
  376. X    {
  377. X        num[i].dnum = (double) i;
  378. X        num[i].inum = i;
  379. X    }
  380. X    printf("\nset to i\n");
  381. X    n1_prnt(stdout, num_prnt, num, 0, 4, sizeof(NUM));
  382. X
  383. X/* renumber the indices a la FORTRAN and print */
  384. X/* the new indices must be used from now on */
  385. X
  386. X    num = (NUM *) n1_renum(num, 0, 4, 1, 5, sizeof(NUM));
  387. X    printf("\nindicies renumbered\n");
  388. X    n1_prnt(stdout, num_prnt, num, 1, 5, sizeof(NUM));
  389. X    printf("\n");
  390. X
  391. X/* free the allocated memory */
  392. X
  393. X    n1_free(num, 1, 5, sizeof(NUM));
  394. X    exit(0);
  395. X}
  396. X
  397. END_OF_FILE
  398. if test 1290 -ne `wc -c <'example2.c'`; then
  399.     echo shar: \"'example2.c'\" unpacked with wrong size!
  400. fi
  401. # end of 'example2.c'
  402. fi
  403. if test -f 'nx.c' -a "${1}" != "-c" ; then 
  404.   echo shar: Will not clobber existing file \"'nx.c'\"
  405. else
  406. echo shar: Extracting \"'nx.c'\" \(6395 characters\)
  407. sed "s/^X//" >'nx.c' <<'END_OF_FILE'
  408. X/*xxalloc.c**************************************************************/     
  409. X/*                                    */
  410. X/*                xxalloc                 */
  411. X/*                                    */
  412. X/*            Placed in the public domain            */
  413. X/*             by Harold G. Walters 1988            */
  414. X/*                                    */
  415. X/*    Bug fixes, ect to walters@ce.okstate.edu until May 1989        */
  416. X/*                                    */
  417. X/*    This software is provided as is.  No claims are made for    */
  418. X/*    this software regarding its fitness and/or correctness for    */
  419. X/*     any purpose.  Use of this software is at the user's own risk.    */
  420. X/*                                    */
  421. X/************************************************************************/
  422. X
  423. X#include <stdio.h>
  424. X
  425. extern char *calloc();
  426. extern void free();
  427. X
  428. X#define STRLEN 132
  429. static char msg[STRLEN];
  430. static long amount = 0L;
  431. X
  432. extern void xx_error();
  433. X
  434. char *xx_alloc(n)
  435. unsigned n;
  436. X{
  437. X    char *m;
  438. X    amount += n;
  439. X    if ((m = calloc(1, n)) == (char *) NULL)
  440. X    {
  441. X        sprintf(msg, "xx_alloc: memory allocation error at %ld bytes\n",
  442. X            amount);
  443. X        xx_error(msg);
  444. X        return((char *) NULL);
  445. X    }
  446. X    return((char *) m);
  447. X}
  448. X
  449. void xx_free(p, n)
  450. char *p;
  451. unsigned n;
  452. X{
  453. X    free(p);
  454. X    amount -= n;
  455. X    return;
  456. X}
  457. X
  458. long xx_amount()
  459. X{
  460. X    return(amount);
  461. X}
  462. X
  463. X/* end index >= begin index */
  464. static void index_test(b, e)
  465. int b, e;
  466. X{
  467. X    if (e < b)
  468. X    {
  469. X        sprintf(msg, "index_test: end index %d < begin index %d\n",
  470. X            e, b);
  471. X        xx_error(msg);
  472. X        /* exit here even if xx_error() returns */
  473. X        /* this is a programming error if this ever happens */
  474. X        exit(2);
  475. X    }
  476. X    return;
  477. X}
  478. X
  479. char *n1_alloc(ib, ie, n)
  480. int ib, ie, n;
  481. X{
  482. X    char *m;
  483. X    index_test(ib, ie);
  484. X    m = (char *) xx_alloc((unsigned) (ie - ib + 1) * n);
  485. X    if (m == (char *) NULL) return((char *) NULL);
  486. X    m -= ib * n;
  487. X    return((char *) m);
  488. X}
  489. X
  490. char *n1_renum(m, ib, ie, nib, nie, n)
  491. char *m;
  492. int ib, ie, nib, nie, n;
  493. X{
  494. X    index_test(ib, ie);
  495. X    index_test(nib, nie);
  496. X    m += (ib - nib) * n;
  497. X    return((char *) m);
  498. X}
  499. X
  500. void n1_free(m, ib, ie, n)
  501. char *m;
  502. int ib, ie, n;
  503. X{
  504. X    index_test(ib, ie);
  505. X    xx_free((char*) (m + ib * n), (unsigned) ((ie - ib + 1) * n));
  506. X    return;
  507. X}
  508. X
  509. void n1_init(m, ib, ie, n, nini)
  510. char *m;
  511. int ib, ie, n;
  512. void (*nini)();
  513. X{
  514. X    int i;
  515. X    index_test(ib, ie);
  516. X    if (nini == (void (*)()) NULL)
  517. X        return;
  518. X    for (i = ib; i <= ie; i++)
  519. X        (*nini)(&m[i*n]);
  520. X    return;
  521. X}
  522. X
  523. void n1_prnt(fp, nprn, m, ib, ie, n)
  524. XFILE *fp;
  525. void (*nprn)();
  526. char *m;
  527. int ib, ie, n;
  528. X{
  529. X    int i;
  530. X    index_test(ib, ie);
  531. X    if (nprn == (void (*)()) NULL)
  532. X        return;
  533. X    for (i = ib; i <= ie; i++)
  534. X        (*nprn)(fp, &m[i*n]);
  535. X    return;
  536. X}
  537. X
  538. char **n2_alloc(ib, ie, jb, je, n)
  539. int ib, ie, jb, je, n;
  540. X{
  541. X    int i;
  542. X    char **m;
  543. X    index_test(ib, ie);
  544. X    index_test(jb, je);
  545. X    m = (char **) xx_alloc((unsigned) (ie - ib + 1) * sizeof(char *));
  546. X    if (m == (char **) NULL) return((char **) NULL);
  547. X    m -= ib;
  548. X    for(i = ib; i <= ie; i++)
  549. X    {
  550. X        m[i] = (char *) xx_alloc((unsigned) (je - jb + 1) * n);
  551. X        if (m[i] == (char *) NULL) return((char **) NULL);
  552. X        m[i] -= jb * n;
  553. X    }
  554. X    return((char **) m);
  555. X}
  556. X
  557. char **n2_renum(m, ib, ie, jb, je, nib, nie, njb, nje, n)
  558. char **m;
  559. int ib, ie, jb, je, nib, nie, njb, nje, n;
  560. X{
  561. X    int i;
  562. X    index_test(ib, ie);
  563. X    index_test(jb, je);
  564. X    index_test(nib, nie);
  565. X    index_test(njb, nje);
  566. X    for(i = ie; i >= ib; i--)
  567. X        m[i] += (jb - njb) * n;
  568. X    m += (ib - nib);
  569. X    return((char **) m);
  570. X}
  571. X
  572. void n2_free(m, ib, ie, jb, je, n)
  573. char **m;
  574. int ib, ie, jb, je, n;
  575. X{
  576. X    int i;
  577. X    index_test(ib, ie);
  578. X    index_test(jb, je);
  579. X    for(i = ie; i >= ib; i--)
  580. X        xx_free((char*) (m[i] + jb * n), 
  581. X            (unsigned) ((je - jb + 1) * n));
  582. X    xx_free((char*) (m + ib), (unsigned) ((ie - ib + 1) * sizeof(char *)));
  583. X    return;
  584. X}
  585. X
  586. void n2_init(m, ib, ie, jb, je, n, nini)
  587. char **m;
  588. int ib, ie, jb, je, n;
  589. void (*nini)();
  590. X{
  591. X    int i, j;
  592. X    index_test(ib, ie);
  593. X    index_test(jb, je);
  594. X    if (nini == (void (*)()) NULL)
  595. X        return;
  596. X    for (i = ib; i <= ie; i++)
  597. X        for (j = jb; j <= je; j++)
  598. X            (*nini)(&m[i][j*n]);
  599. X    return;
  600. X}
  601. X
  602. void n2_prnt(fp, nprn, m, ib, ie, jb, je, n)
  603. XFILE *fp;
  604. void (*nprn)();
  605. char **m;
  606. int ib, ie, jb, je, n;
  607. X{
  608. X    int i, j;
  609. X    index_test(ib, ie);
  610. X    index_test(jb, je);
  611. X    if (nprn == (void (*)()) NULL)
  612. X        return;
  613. X    for (i = ib; i <= ie; i++)
  614. X        for (j = jb; j <= je; j++)
  615. X            (*nprn)(fp, &m[i][j*n]);
  616. X    return;
  617. X}
  618. X
  619. char ***n3_alloc(ib, ie, jb, je, kb, ke, n)
  620. int ib, ie, jb, je, kb, ke, n;
  621. X{
  622. X    int i, j;
  623. X    char ***m;
  624. X    index_test(ib, ie);
  625. X    index_test(jb, je);
  626. X    index_test(kb, ke);
  627. X    m = (char ***) xx_alloc((unsigned) (ie - ib + 1) * sizeof(char **));
  628. X    if (m == (char ***) NULL) return((char ***) NULL);
  629. X    m -= ib;
  630. X    for(i = ib; i <= ie; i++)
  631. X    {
  632. X        m[i] = (char **) xx_alloc((unsigned) (je - jb + 1) * 
  633. X            sizeof(char *));
  634. X        if (m[i] == (char **) NULL) return((char ***) NULL);
  635. X        m[i] -= jb;
  636. X        for(j = jb; j <= je; j++)
  637. X        {
  638. X            m[i][j] = (char *) xx_alloc((unsigned) (ke - kb + 1)
  639. X                * n);
  640. X            if (m[i][j] == (char *) NULL) return((char ***) NULL);
  641. X            m[i][j] -= kb * n;
  642. X        }
  643. X    }
  644. X    return((char ***) m);
  645. X}
  646. X
  647. char ***n3_renum(m, ib, ie, jb, je, kb, ke, nib, nie, njb, nje, nkb, nke, n)
  648. char ***m;
  649. int ib, ie, jb, je, kb, ke, nib, nie, njb, nje, nkb, nke, n;
  650. X{
  651. X    int i, j;
  652. X    index_test(ib, ie);
  653. X    index_test(jb, je);
  654. X    index_test(kb, ke);
  655. X    index_test(nib, nie);
  656. X    index_test(njb, nje);
  657. X    index_test(nkb, nke);
  658. X    for(i = ie; i >= ib; i--)
  659. X        for (j = je; j >= jb; j--)
  660. X            m[i][j] += (kb - nkb) * n;
  661. X    for(i = ie; i >= ib; i--)
  662. X        m[i] += (jb - njb);
  663. X    m += (ib - nib);
  664. X    return((char ***) m);
  665. X}
  666. X
  667. void n3_free(m, ib, ie, jb, je, kb, ke, n)
  668. char ***m;
  669. int ib, ie, jb, je, kb, ke, n;
  670. X{
  671. X    int i, j;
  672. X    index_test(ib, ie);
  673. X    index_test(jb, je);
  674. X    index_test(kb, ke);
  675. X    for(i = ie; i >= ib; i--)
  676. X        for (j = je; j >= jb; j--)
  677. X            xx_free((char*) (m[i][j] + kb * n),
  678. X                (unsigned) (ke - kb + 1) * n);
  679. X    for(i = ie; i >= ib; i--)
  680. X        xx_free((char*) (m[i] + jb), 
  681. X            (unsigned) ((je - jb + 1) * sizeof(char *)));
  682. X    xx_free((char*) (m + ib),
  683. X        (unsigned) ((ie - ib + 1) * sizeof(char **)));
  684. X    return;
  685. X}
  686. X
  687. void n3_init(m, ib, ie, jb, je, kb, ke, n, nini)
  688. char ***m;
  689. int ib, ie, jb, je, kb, ke, n;
  690. void (*nini)();
  691. X{
  692. X    int i, j, k;
  693. X    index_test(ib, ie);
  694. X    index_test(jb, je);
  695. X    index_test(kb, ke);
  696. X    if (nini == (void (*)()) NULL)
  697. X        return;
  698. X    for (i = ib; i <= ie; i++)
  699. X        for (j = jb; j <= je; j++)
  700. X            for (k = kb; k <= ke; k++)
  701. X                (*nini)(&m[i][j][k*n]);
  702. X    return;
  703. X}
  704. X
  705. void n3_prnt(fp, nprn, m, ib, ie, jb, je, kb, ke, n)
  706. XFILE *fp;
  707. void (*nprn)();
  708. char ***m;
  709. int ib, ie, jb, je, kb, ke, n;
  710. X{
  711. X    int i, j, k;
  712. X    index_test(ib, ie);
  713. X    index_test(jb, je);
  714. X    index_test(kb, ke);
  715. X    if (nprn == (void (*)()) NULL)
  716. X        return;
  717. X    for (i = ib; i <= ie; i++)
  718. X    {
  719. X        fprintf(fp, "%d\n", i);
  720. X        for (j = jb; j <= je; j++)
  721. X            for (k = kb; k <= ke; k++)
  722. X                (*nprn)(fp, &m[i][j][k*n]);
  723. X    }
  724. X    return;
  725. X}
  726. X
  727. X
  728. END_OF_FILE
  729. if test 6395 -ne `wc -c <'nx.c'`; then
  730.     echo shar: \"'nx.c'\" unpacked with wrong size!
  731. fi
  732. # end of 'nx.c'
  733. fi
  734. if test -f 'nx.h' -a "${1}" != "-c" ; then 
  735.   echo shar: Will not clobber existing file \"'nx.h'\"
  736. else
  737. echo shar: Extracting \"'nx.h'\" \(1057 characters\)
  738. sed "s/^X//" >'nx.h' <<'END_OF_FILE'
  739. X/*xxalloc.h**************************************************************/     
  740. X/*                                    */
  741. X/*                xxalloc                 */
  742. X/*                                    */
  743. X/*            Placed in the public domain            */
  744. X/*             by Harold G. Walters 1988            */
  745. X/*                                    */
  746. X/*    Bug fixes, ect to walters@ce.okstate.edu until May 1989        */
  747. X/*                                    */
  748. X/*    This software is provided as is.  No claims are made for    */
  749. X/*    this software regarding its fitness and/or correctness for    */
  750. X/*     any purpose.  Use of this software is at the user's own risk.    */
  751. X/*                                    */
  752. X/************************************************************************/
  753. X
  754. extern void xx_error();
  755. extern char *xx_alloc();
  756. extern void xx_free();
  757. extern long xx_amount();
  758. X
  759. X/* size n */
  760. extern char *n1_alloc();
  761. extern char *n1_renum();
  762. extern void n1_free();
  763. extern void n1_init();
  764. extern void n1_prnt();
  765. extern char **n2_alloc();
  766. extern char **n2_renum();
  767. extern void n2_free();
  768. extern void n2_init();
  769. extern void n2_prnt();
  770. extern char ***n3_alloc();
  771. extern char ***n3_renum();
  772. extern void n3_free();
  773. extern void n3_init();
  774. extern void n3_prnt();
  775. X
  776. END_OF_FILE
  777. if test 1057 -ne `wc -c <'nx.h'`; then
  778.     echo shar: \"'nx.h'\" unpacked with wrong size!
  779. fi
  780. # end of 'nx.h'
  781. fi
  782. if test -f 'nxtest.c' -a "${1}" != "-c" ; then 
  783.   echo shar: Will not clobber existing file \"'nxtest.c'\"
  784. else
  785. echo shar: Extracting \"'nxtest.c'\" \(3276 characters\)
  786. sed "s/^X//" >'nxtest.c' <<'END_OF_FILE'
  787. X/*xxtest.c***************************************************************/     
  788. X/*                                    */
  789. X/*                xxalloc                 */
  790. X/*                                    */
  791. X/*            Placed in the public domain            */
  792. X/*             by Harold G. Walters 1988            */
  793. X/*                                    */
  794. X/*    Bug fixes, ect to walters@ce.okstate.edu until May 1989        */
  795. X/*                                    */
  796. X/*    This software is provided as is.  No claims are made for    */
  797. X/*    this software regarding its fitness and/or correctness for    */
  798. X/*     any purpose.  Use of this software is at the user's own risk.    */
  799. X/*                                    */
  800. X/************************************************************************/
  801. X
  802. X#include <stdio.h>
  803. X#include "xxalloc.h"
  804. X
  805. X#define STRLEN 132
  806. static char msg[STRLEN];
  807. X
  808. X/* 3*(NE+NO) <= 126 for char */
  809. X
  810. X/* begin */
  811. X#define NB -2
  812. X/* end */
  813. X#define NE 2
  814. X/* offset */
  815. X#define NO 9
  816. X
  817. typedef struct
  818. X{
  819. X    int l;
  820. X    char junk;
  821. X} STU;
  822. X
  823. main()
  824. X{
  825. X    int i, j, k;    
  826. X    if (3*(NE+NO) > 126)
  827. X    {
  828. X        sprintf(msg, "3*(NE+NO) == %d but must be <= 126", 3*(NE+NO));
  829. X        xx_error(msg);
  830. X    }
  831. X    {
  832. X        STU *n1, **n2, ***n3;
  833. X
  834. X        printf("checking STU 1 \n");
  835. X        if (xx_amount() != 0L)
  836. X            printf("STU: amount == %ld", xx_amount());
  837. X        n1 = (STU *) n1_alloc(NB, NE, sizeof(STU));
  838. X         for (i = NB; i <= NE; i++)
  839. X             n1[i].l = i;
  840. X         for (i = NB; i <= NE; i++)
  841. X             if (n1[i].l != i)
  842. X            printf("STU: after allocate n1[%d].l = %d != %d\n",
  843. X                i, n1[i].l, i);
  844. X        n1 = (STU *) n1_renum(n1, NB, NE, NB+NO, NE+NO, sizeof(STU));
  845. X         for (i = NB+NO; i <= NE+NO; i++)
  846. X            if (n1[i].l != i-NO)
  847. X            printf("STU: after renum n1[%d].l = %d != %d\n",
  848. X                i, n1[i].l, i-NO);
  849. X        n1_free(n1, NB+NO, NE+NO, sizeof(STU));
  850. X        
  851. X
  852. X        printf("checking STU 2 \n");
  853. X        if (xx_amount() != 0L)
  854. X            printf("STU: amount == %ld", xx_amount());
  855. X        n2 = (STU **) n2_alloc(NB, NE, NB, NE, sizeof(STU));
  856. X         for (i = NB; i <= NE; i++)
  857. X             for (j = NB; j <= NE; j++)
  858. X                 n2[i][j].l = i + j;
  859. X         for (i = NB; i <= NE; i++)
  860. X             for (j = NB; j <= NE; j++)
  861. X                 if (n2[i][j].l != i+j)
  862. X            printf("STU: after allocate n2[%d][%d].l = %d != %d\n",
  863. X                    i, j, n2[i][j].l, i+j);
  864. X        n2 = (STU **) n2_renum(n2, NB, NE, NB, NE,
  865. X            NB+NO, NE+NO, NB+NO, NE+NO, sizeof(STU));
  866. X         for (i = NB+NO; i <= NE+NO; i++)
  867. X             for (j = NB+NO; j <= NE+NO; j++)
  868. X                 if (n2[i][j].l != i+j-NO-NO)
  869. X            printf("STU: after renum n2[%d][%d].l = %d != %d\n",
  870. X                    i, j, n2[i][j].l, i+j-NO-NO);
  871. X        n2_free(n2, NB+NO, NE+NO, NB+NO, NE+NO, sizeof(STU));
  872. X
  873. X        printf("checking STU 3 \n");
  874. X        if (xx_amount() != 0L)
  875. X            printf("STU: amount == %ld", xx_amount());
  876. X        n3 = (STU ***) n3_alloc(NB, NE, NB, NE, NB, NE, sizeof(STU));
  877. X         for (i = NB; i <= NE; i++)
  878. X             for (j = NB; j <= NE; j++)
  879. X                 for (k = NB; k <= NE; k++)
  880. X                     n3[i][j][k].l = i + j + k;
  881. X         for (i = NB; i <= NE; i++)
  882. X             for (j = NB; j <= NE; j++)
  883. X                 for (k = NB; k <= NE; k++)
  884. X                     if (n3[i][j][k].l != i+j+k)
  885. X        printf("STU: after allocate n3[%d][%d][%d].l = %d != %d\n",
  886. X                        i, j, k, n3[i][j][k].l, i+j+k);
  887. X        n3 = (STU ***) n3_renum(n3, NB, NE, NB, NE, NB, NE, 
  888. X            NB+NO, NE+NO, NB+NO, NE+NO, NB+NO, NE+NO, sizeof(STU));
  889. X         for (i = NB+NO; i <= NE+NO; i++)
  890. X             for (j = NB+NO; j <= NE+NO; j++)
  891. X                 for (k = NB+NO; k <= NE+NO; k++)
  892. X                     if (n3[i][j][k].l != i+j+k-3*NO)
  893. X        printf("STU: after renum n3[%d][%d][%d].l = %d != %d\n",
  894. X                    i, j, k, n3[i][j][k].l, i+j+k-3*NO);
  895. X        n3_free(n3, NB+NO, NE+NO, NB+NO, NE+NO, NB+NO, NE+NO,
  896. X            sizeof(STU));
  897. X    }
  898. END_OF_FILE
  899. if test 3276 -ne `wc -c <'nxtest.c'`; then
  900.     echo shar: \"'nxtest.c'\" unpacked with wrong size!
  901. fi
  902. # end of 'nxtest.c'
  903. fi
  904. if test -f 'proto.h' -a "${1}" != "-c" ; then 
  905.   echo shar: Will not clobber existing file \"'proto.h'\"
  906. else
  907. echo shar: Extracting \"'proto.h'\" \(7999 characters\)
  908. sed "s/^X//" >'proto.h' <<'END_OF_FILE'
  909. X/* proto.h */
  910. static  void index_test(int b,int e);
  911. extern  void xx_error(char *s);
  912. extern  char *xx_alloc(unsigned int n);
  913. extern  void xx_free(char *p,unsigned int n);
  914. extern  long xx_amount(void );
  915. extern  char *n1_alloc(int ib,int ie,int n);
  916. extern  char *n1_renum(char *m,int ib,int ie,int nib,int nie,
  917. X    int n);
  918. extern  void n1_free(char *m,int ib,int ie,int n);
  919. extern  void n1_init(char *m,int ib,int ie,int n,void (*nini)());
  920. extern  void n1_prnt(FILE *fp,void (*nprn)(),char *m,int ib,int ie,
  921. X    int n);
  922. extern  char **n2_alloc(int ib,int ie,int jb,int je,int n);
  923. extern  char **n2_renum(char **m,int ib,int ie,int jb,int je,
  924. X    int nib,int nie,int njb,int nje,int n);
  925. extern  void n2_free(char **m,int ib,int ie,int jb,int je,int n);
  926. extern  void n2_init(char **m,int ib,int ie,int jb,int je,int n,
  927. X    void (*nini)());
  928. extern  void n2_prnt(FILE *fp,void (*nprn)(),char **m,int ib,
  929. X    int ie,int jb,int je,int n);
  930. extern  char ***n3_alloc(int ib,int ie,int jb,int je,int kb,int ke,
  931. X    int n);
  932. extern  char ***n3_renum(char ***m,int ib,int ie,int jb,int je,
  933. X    int kb,int ke,int nib,int nie,int njb,int nje,int nkb,
  934. X    int nke,int n);
  935. extern  void n3_free(char ***m,int ib,int ie,int jb,int je,int kb,
  936. X    int ke,int n);
  937. extern  void n3_init(char ***m,int ib,int ie,int jb,int je,int kb,
  938. X    int ke,int n,void (*nini)());
  939. extern  void n3_prnt(FILE *fp,void (*nprn)(),char ***m,int ib,
  940. X    int ie,int jb,int je,int kb,int ke,int n);
  941. extern  char *c1_alloc(int ib,int ie);
  942. extern  char *c1_renum(char *m,int ib,int ie,int nib,int nie);
  943. extern  void c1_free(char *m,int ib,int ie);
  944. extern  void c1_init(char *m,int ib,int ie,char ini);
  945. extern  void c1_prnt(FILE *fp,char *fmt,char *m,int ib,int ie);
  946. extern  char **c2_alloc(int ib,int ie,int jb,int je);
  947. extern  char **c2_renum(char **m,int ib,int ie,int jb,int je,
  948. X    int nib,int nie,int njb,int nje);
  949. extern  void c2_free(char **m,int ib,int ie,int jb,int je);
  950. extern  void c2_init(char **m,int ib,int ie,int jb,int je,char ini);
  951. extern  void c2_prnt(FILE *fp,char *fmt,char **m,int ib,int ie,
  952. X    int jb,int je);
  953. extern  char ***c3_alloc(int ib,int ie,int jb,int je,int kb,int ke);
  954. extern  char ***c3_renum(char ***m,int ib,int ie,int jb,int je,
  955. X    int kb,int ke,int nib,int nie,int njb,int nje,int nkb,
  956. X    int nke);
  957. extern  void c3_free(char ***m,int ib,int ie,int jb,int je,int kb,
  958. X    int ke);
  959. extern  void c3_init(char ***m,int ib,int ie,int jb,int je,int kb,
  960. X    int ke,char ini);
  961. extern  void c3_prnt(FILE *fp,char *fmt,char ***m,int ib,int ie,
  962. X    int jb,int je,int kb,int ke);
  963. extern  short *s1_alloc(int ib,int ie);
  964. extern  short *s1_renum(short *m,int ib,int ie,int nib,int nie);
  965. extern  void s1_free(short *m,int ib,int ie);
  966. extern  void s1_init(short *m,int ib,int ie,short ini);
  967. extern  void s1_prnt(FILE *fp,char *fmt,short *m,int ib,int ie);
  968. extern  short **s2_alloc(int ib,int ie,int jb,int je);
  969. extern  short **s2_renum(short **m,int ib,int ie,int jb,int je,
  970. X    int nib,int nie,int njb,int nje);
  971. extern  void s2_free(short **m,int ib,int ie,int jb,int je);
  972. extern  void s2_init(short **m,int ib,int ie,int jb,int je,short ini);
  973. extern  void s2_prnt(FILE *fp,char *fmt,short **m,int ib,int ie,
  974. X    int jb,int je);
  975. extern  short ***s3_alloc(int ib,int ie,int jb,int je,int kb,
  976. X    int ke);
  977. extern  short ***s3_renum(short ***m,int ib,int ie,int jb,int je,
  978. X    int kb,int ke,int nib,int nie,int njb,int nje,int nkb,
  979. X    int nke);
  980. extern  void s3_free(short ***m,int ib,int ie,int jb,int je,int kb,
  981. X    int ke);
  982. extern  void s3_init(short ***m,int ib,int ie,int jb,int je,int kb,
  983. X    int ke,short ini);
  984. extern  void s3_prnt(FILE *fp,char *fmt,short ***m,int ib,int ie,
  985. X    int jb,int je,int kb,int ke);
  986. extern  long *l1_alloc(int ib,int ie);
  987. extern  long *l1_renum(long *m,int ib,int ie,int nib,int nie);
  988. extern  void l1_free(long *m,int ib,int ie);
  989. extern  void l1_init(long *m,int ib,int ie,long ini);
  990. extern  void l1_prnt(FILE *fp,char *fmt,long *m,int ib,int ie);
  991. extern  long **l2_alloc(int ib,int ie,int jb,int je);
  992. extern  long **l2_renum(long **m,int ib,int ie,int jb,int je,
  993. X    int nib,int nie,int njb,int nje);
  994. extern  void l2_free(long **m,int ib,int ie,int jb,int je);
  995. extern  void l2_init(long **m,int ib,int ie,int jb,int je,long ini);
  996. extern  void l2_prnt(FILE *fp,char *fmt,long **m,int ib,int ie,
  997. X    int jb,int je);
  998. extern  long ***l3_alloc(int ib,int ie,int jb,int je,int kb,int ke);
  999. extern  long ***l3_renum(long ***m,int ib,int ie,int jb,int je,
  1000. X    int kb,int ke,int nib,int nie,int njb,int nje,int nkb,
  1001. X    int nke);
  1002. extern  void l3_free(long ***m,int ib,int ie,int jb,int je,int kb,
  1003. X    int ke);
  1004. extern  void l3_init(long ***m,int ib,int ie,int jb,int je,int kb,
  1005. X    int ke,long ini);
  1006. extern  void l3_prnt(FILE *fp,char *fmt,long ***m,int ib,int ie,
  1007. X    int jb,int je,int kb,int ke);
  1008. extern  int *i1_alloc(int ib,int ie);
  1009. extern  int *i1_renum(int *m,int ib,int ie,int nib,int nie);
  1010. extern  void i1_free(int *m,int ib,int ie);
  1011. extern  void i1_init(int *m,int ib,int ie,int ini);
  1012. extern  void i1_prnt(FILE *fp,char *fmt,int *m,int ib,int ie);
  1013. extern  int **i2_alloc(int ib,int ie,int jb,int je);
  1014. extern  int **i2_renum(int **m,int ib,int ie,int jb,int je,int nib,
  1015. X    int nie,int njb,int nje);
  1016. extern  void i2_free(int **m,int ib,int ie,int jb,int je);
  1017. extern  void i2_init(int **m,int ib,int ie,int jb,int je,int ini);
  1018. extern  void i2_prnt(FILE *fp,char *fmt,int **m,int ib,int ie,
  1019. X    int jb,int je);
  1020. extern  int ***i3_alloc(int ib,int ie,int jb,int je,int kb,int ke);
  1021. extern  int ***i3_renum(int ***m,int ib,int ie,int jb,int je,
  1022. X    int kb,int ke,int nib,int nie,int njb,int nje,int nkb,
  1023. X    int nke);
  1024. extern  void i3_free(int ***m,int ib,int ie,int jb,int je,int kb,
  1025. X    int ke);
  1026. extern  void i3_init(int ***m,int ib,int ie,int jb,int je,int kb,
  1027. X    int ke,int ini);
  1028. extern  void i3_prnt(FILE *fp,char *fmt,int ***m,int ib,int ie,
  1029. X    int jb,int je,int kb,int ke);
  1030. extern  float *f1_alloc(int ib,int ie);
  1031. extern  float *f1_renum(float *m,int ib,int ie,int nib,int nie);
  1032. extern  void f1_free(float *m,int ib,int ie);
  1033. extern  void f1_init(float *m,int ib,int ie,double ini);
  1034. extern  void f1_prnt(FILE *fp,char *fmt,float *m,int ib,int ie);
  1035. extern  float **f2_alloc(int ib,int ie,int jb,int je);
  1036. extern  float **f2_renum(float **m,int ib,int ie,int jb,int je,
  1037. X    int nib,int nie,int njb,int nje);
  1038. extern  void f2_free(float **m,int ib,int ie,int jb,int je);
  1039. extern  void f2_init(float **m,int ib,int ie,int jb,int je,double ini);
  1040. extern  void f2_prnt(FILE *fp,char *fmt,float **m,int ib,int ie,
  1041. X    int jb,int je);
  1042. extern  float ***f3_alloc(int ib,int ie,int jb,int je,int kb,
  1043. X    int ke);
  1044. extern  float ***f3_renum(float ***m,int ib,int ie,int jb,int je,
  1045. X    int kb,int ke,int nib,int nie,int njb,int nje,int nkb,
  1046. X    int nke);
  1047. extern  void f3_free(float ***m,int ib,int ie,int jb,int je,int kb,
  1048. X    int ke);
  1049. extern  void f3_init(float ***m,int ib,int ie,int jb,int je,int kb,
  1050. X    int ke,double ini);
  1051. extern  void f3_prnt(FILE *fp,char *fmt,float ***m,int ib,int ie,
  1052. X    int jb,int je,int kb,int ke);
  1053. extern  double *d1_alloc(int ib,int ie);
  1054. extern  double *d1_renum(double *m,int ib,int ie,int nib,int nie);
  1055. extern  void d1_free(double *m,int ib,int ie);
  1056. extern  void d1_init(double *m,int ib,int ie,double ini);
  1057. extern  void d1_prnt(FILE *fp,char *fmt,double *m,int ib,int ie);
  1058. extern  double **d2_alloc(int ib,int ie,int jb,int je);
  1059. extern  double **d2_renum(double **m,int ib,int ie,int jb,int je,
  1060. X    int nib,int nie,int njb,int nje);
  1061. extern  void d2_free(double **m,int ib,int ie,int jb,int je);
  1062. extern  void d2_init(double **m,int ib,int ie,int jb,int je,double ini);
  1063. extern  void d2_prnt(FILE *fp,char *fmt,double **m,int ib,int ie,
  1064. X    int jb,int je);
  1065. extern  double ***d3_alloc(int ib,int ie,int jb,int je,int kb,
  1066. X    int ke);
  1067. extern  double ***d3_renum(double ***m,int ib,int ie,int jb,int je,
  1068. X    int kb,int ke,int nib,int nie,int njb,int nje,int nkb,
  1069. X    int nke);
  1070. extern  void d3_free(double ***m,int ib,int ie,int jb,int je,
  1071. X    int kb,int ke);
  1072. extern  void d3_init(double ***m,int ib,int ie,int jb,int je,
  1073. X    int kb,int ke,double ini);
  1074. extern  void d3_prnt(FILE *fp,char *fmt,double ***m,int ib,int ie,
  1075. X    int jb,int je,int kb,int ke);
  1076. END_OF_FILE
  1077. if test 7999 -ne `wc -c <'proto.h'`; then
  1078.     echo shar: \"'proto.h'\" unpacked with wrong size!
  1079. fi
  1080. # end of 'proto.h'
  1081. fi
  1082. if test -f 'tx.c' -a "${1}" != "-c" ; then 
  1083.   echo shar: Will not clobber existing file \"'tx.c'\"
  1084. else
  1085. echo shar: Extracting \"'tx.c'\" \(4732 characters\)
  1086. sed "s/^X//" >'tx.c' <<'END_OF_FILE'
  1087. X/* type allocation */
  1088. X
  1089. type *t1_alloc(ib, ie)
  1090. int ib, ie;
  1091. X{
  1092. X    type *m;
  1093. X    index_test(ib, ie);
  1094. X    m = (type *) xx_alloc((unsigned) (ie - ib + 1) * sizeof(type));
  1095. X    if (m == (type *) NULL) return((type *) NULL);
  1096. X    m -= ib;
  1097. X    return((type *) m);
  1098. X}
  1099. X
  1100. type *t1_renum(m, ib, ie, nib, nie)
  1101. type *m;
  1102. int ib, ie, nib, nie;
  1103. X{
  1104. X    index_test(ib, ie);
  1105. X    index_test(nib, nie);
  1106. X    m += (ib - nib);
  1107. X    return((type *) m);
  1108. X}
  1109. X
  1110. void t1_free(m, ib, ie)
  1111. type *m;
  1112. int ib, ie;
  1113. X{
  1114. X    index_test(ib, ie);
  1115. X    xx_free((char*) (m + ib), (unsigned) ((ie - ib + 1) * sizeof(type)));
  1116. X    return;
  1117. X}
  1118. X
  1119. void t1_init(m, ib, ie, ini)
  1120. type *m;
  1121. int ib, ie;
  1122. type ini;
  1123. X{
  1124. X    int i;
  1125. X    index_test(ib, ie);
  1126. X    for (i = ib; i <= ie; i++)
  1127. X        m[i] = ini;
  1128. X    return;
  1129. X}
  1130. X
  1131. void t1_prnt(fp, fmt, m, ib, ie)
  1132. XFILE *fp;
  1133. char *fmt;
  1134. type *m;
  1135. int ib, ie;
  1136. X{
  1137. X    int i;
  1138. X    index_test(ib, ie);
  1139. X    for (i = ib; i <= ie; i++)
  1140. X        fprintf(fp, fmt, m[i]);
  1141. X    fprintf(fp, "\n");
  1142. X    return;
  1143. X}
  1144. X    
  1145. type **t2_alloc(ib, ie, jb, je)
  1146. int ib, ie, jb, je;
  1147. X{
  1148. X    int i;
  1149. X    type **m;
  1150. X    index_test(ib, ie);
  1151. X    index_test(jb, je);
  1152. X    m = (type **) xx_alloc((unsigned) (ie - ib + 1) *
  1153. X        sizeof(type *));
  1154. X    if (m == (type **) NULL) return((type **) NULL);
  1155. X    m -= ib;
  1156. X    for(i = ib; i <= ie; i++)
  1157. X    {
  1158. X        m[i] = (type *) xx_alloc((unsigned) (je - jb + 1) *
  1159. X            sizeof(type));
  1160. X        if (m[i] == (type *) NULL) return((type **) NULL);
  1161. X        m[i] -= jb;
  1162. X    }
  1163. X    return((type **) m);
  1164. X}
  1165. X
  1166. type **t2_renum(m, ib, ie, jb, je, nib, nie, njb, nje)
  1167. type **m;
  1168. int ib, ie, jb, je, nib, nie, njb, nje;
  1169. X{
  1170. X    int i;
  1171. X    index_test(ib, ie);
  1172. X    index_test(jb, je);
  1173. X    index_test(nib, nie);
  1174. X    index_test(njb, nje);
  1175. X    for(i = ie; i >= ib; i--)
  1176. X        m[i] += (jb - njb);
  1177. X    m += (ib - nib);
  1178. X    return((type **) m);
  1179. X}
  1180. X
  1181. void t2_free(m, ib, ie, jb, je)
  1182. type **m;
  1183. int ib, ie, jb, je;
  1184. X{
  1185. X    int i;
  1186. X    index_test(ib, ie);
  1187. X    index_test(jb, je);
  1188. X    for(i = ie; i >= ib; i--)
  1189. X        xx_free((char*) (m[i] + jb), 
  1190. X            (unsigned) ((je - jb + 1) * sizeof(type)));
  1191. X    xx_free((char*) (m + ib), (unsigned) ((ie - ib + 1) * sizeof(type *)));
  1192. X    return;
  1193. X}
  1194. X
  1195. void t2_init(m, ib, ie, jb, je, ini)
  1196. type **m;
  1197. int ib, ie, jb, je;
  1198. type ini;
  1199. X{
  1200. X    int i, j;
  1201. X    index_test(ib, ie);
  1202. X    index_test(jb, je);
  1203. X    for (i = ib; i <= ie; i++)
  1204. X        for (j = jb; j <= je; j++)
  1205. X            m[i][j] = ini;
  1206. X    return;
  1207. X}
  1208. X
  1209. void t2_prnt(fp, fmt, m, ib, ie, jb, je)
  1210. XFILE *fp;
  1211. char *fmt;
  1212. type **m;
  1213. int ib, ie, jb, je;
  1214. X{
  1215. X    int i, j;
  1216. X    index_test(ib, ie);
  1217. X    index_test(jb, je);
  1218. X    for (i = ib; i <= ie; i++)
  1219. X    {
  1220. X        for (j = jb; j <= je; j++)
  1221. X            fprintf(fp, fmt, m[i][j]);
  1222. X        fprintf(fp, "\n");
  1223. X    }
  1224. X    return;
  1225. X}
  1226. X
  1227. type ***t3_alloc(ib, ie, jb, je, kb, ke)
  1228. int ib, ie, jb, je, kb, ke;
  1229. X{
  1230. X    int i, j;
  1231. X    type ***m;
  1232. X    index_test(ib, ie);
  1233. X    index_test(jb, je);
  1234. X    index_test(kb, ke);
  1235. X    m = (type ***) xx_alloc((unsigned) (ie - ib + 1) * 
  1236. X        sizeof(type **));
  1237. X    if (m == (type ***) NULL) return((type ***) NULL);
  1238. X    m -= ib;
  1239. X    for(i = ib; i <= ie; i++)
  1240. X    {
  1241. X        m[i] = (type **) xx_alloc((unsigned) (je - jb + 1) * 
  1242. X            sizeof(type *));
  1243. X        if (m[i] == (type **) NULL) return((type ***) NULL);
  1244. X        m[i] -= jb;
  1245. X        for(j = jb; j <= je; j++)
  1246. X        {
  1247. X            m[i][j] = (type *) xx_alloc((unsigned) (ke - kb + 1) *
  1248. X                sizeof(type));
  1249. X            if (m[i][j] == (type *) NULL) return((type ***) NULL);
  1250. X            m[i][j] -= kb;
  1251. X        }
  1252. X    }
  1253. X    return((type ***) m);
  1254. X}
  1255. X
  1256. type ***t3_renum(m, ib, ie, jb, je, kb, ke, nib, nie, njb, nje, nkb, nke)
  1257. type ***m;
  1258. int ib, ie, jb, je, kb, ke, nib, nie, njb, nje, nkb, nke;
  1259. X{
  1260. X    int i, j;
  1261. X    index_test(ib, ie);
  1262. X    index_test(jb, je);
  1263. X    index_test(kb, ke);
  1264. X    index_test(nib, nie);
  1265. X    index_test(njb, nje);
  1266. X    index_test(nkb, nke);
  1267. X    for(i = ie; i >= ib; i--)
  1268. X        for (j = je; j >= jb; j--)
  1269. X            m[i][j] += (kb - nkb);
  1270. X    for(i = ie; i >= ib; i--)
  1271. X        m[i] += (jb - njb);
  1272. X    m += (ib - nib);
  1273. X    return((type ***) m);
  1274. X}
  1275. X
  1276. void t3_free(m, ib, ie, jb, je, kb, ke)
  1277. type ***m;
  1278. int ib, ie, jb, je, kb, ke;
  1279. X{
  1280. X    int i, j;
  1281. X    index_test(ib, ie);
  1282. X    index_test(jb, je);
  1283. X    index_test(kb, ke);
  1284. X    for(i = ie; i >= ib; i--)
  1285. X        for (j = je; j >= jb; j--)
  1286. X            xx_free((char*) (m[i][j] + kb),
  1287. X                (unsigned) ((ke - kb + 1) * sizeof(type)));
  1288. X    for(i = ie; i >= ib; i--)
  1289. X        xx_free((char*) (m[i] + jb), 
  1290. X            (unsigned) ((je - jb + 1) * sizeof(type *)));
  1291. X    xx_free((char*) (m + ib),
  1292. X        (unsigned) ((ie - ib + 1) * sizeof(type **)));
  1293. X    return;
  1294. X}
  1295. X
  1296. void t3_init(m, ib, ie, jb, je, kb, ke, ini)
  1297. type ***m;
  1298. int ib, ie, jb, je, kb, ke;
  1299. type ini;
  1300. X{
  1301. X    int i, j, k;
  1302. X    index_test(ib, ie);
  1303. X    index_test(jb, je);
  1304. X    index_test(kb, ke);
  1305. X    for (i = ib; i <= ie; i++)
  1306. X        for (j = jb; j <= je; j++)
  1307. X            for (k = kb; k <= ke; k++)
  1308. X                m[i][j][k] = ini;
  1309. X    return;
  1310. X}
  1311. X
  1312. void t3_prnt(fp, fmt, m, ib, ie, jb, je, kb, ke)
  1313. XFILE *fp;
  1314. char *fmt;
  1315. type ***m;
  1316. int ib, ie, jb, je, kb, ke;
  1317. X{
  1318. X    int i, j, k;
  1319. X    index_test(ib, ie);
  1320. X    index_test(jb, je);
  1321. X    index_test(kb, ke);
  1322. X    for (i = ib; i <= ie; i++)
  1323. X    {
  1324. X        fprintf(fp, "%d\n", i);
  1325. X        for (j = jb; j <= je; j++)
  1326. X        {
  1327. X            for (k = kb; k <= ke; k++)
  1328. X                fprintf(fp, fmt, m[i][j][k]);
  1329. X            fprintf(fp, "\n");
  1330. X        }
  1331. X    }
  1332. X    return;
  1333. X}
  1334. X
  1335. X
  1336. END_OF_FILE
  1337. if test 4732 -ne `wc -c <'tx.c'`; then
  1338.     echo shar: \"'tx.c'\" unpacked with wrong size!
  1339. fi
  1340. # end of 'tx.c'
  1341. fi
  1342. if test -f 'tx.h' -a "${1}" != "-c" ; then 
  1343.   echo shar: Will not clobber existing file \"'tx.h'\"
  1344. else
  1345. echo shar: Extracting \"'tx.h'\" \(375 characters\)
  1346. sed "s/^X//" >'tx.h' <<'END_OF_FILE'
  1347. X/* type */
  1348. extern type *t1_alloc();
  1349. extern type *t1_renum();
  1350. extern void t1_free();
  1351. extern void t1_init();
  1352. extern void t1_prnt();
  1353. extern type **t2_alloc();
  1354. extern type **t2_renum();
  1355. extern void t2_free();
  1356. extern void t2_init();
  1357. extern void t2_prnt();
  1358. extern type ***t3_alloc();
  1359. extern type ***t3_renum();
  1360. extern void t3_free();
  1361. extern void t3_init();
  1362. extern void t3_prnt();
  1363. X
  1364. END_OF_FILE
  1365. if test 375 -ne `wc -c <'tx.h'`; then
  1366.     echo shar: \"'tx.h'\" unpacked with wrong size!
  1367. fi
  1368. # end of 'tx.h'
  1369. fi
  1370. if test -f 'txtest.c' -a "${1}" != "-c" ; then 
  1371.   echo shar: Will not clobber existing file \"'txtest.c'\"
  1372. else
  1373. echo shar: Extracting \"'txtest.c'\" \(2199 characters\)
  1374. sed "s/^X//" >'txtest.c' <<'END_OF_FILE'
  1375. X    {
  1376. X        type *t1, **t2, ***t3;
  1377. X    
  1378. X        printf("checking type 1 \n");
  1379. X        if (xx_amount() != 0L)
  1380. X            printf("type: amount == %ld", xx_amount());
  1381. X        t1 = t1_alloc(NB, NE);
  1382. X         for (i = NB; i <= NE; i++)
  1383. X             t1[i] = (type) i;
  1384. X         for (i = NB; i <= NE; i++)
  1385. X             if (t1[i] != (type) i)
  1386. X            printf("type: after allocate t1[%d] = %t != %d\n",
  1387. X                i, t1[i], i);
  1388. X        t1 = t1_renum(t1, NB, NE, NB+NO, NE+NO);
  1389. X         for (i = NB+NO; i <= NE+NO; i++)
  1390. X            if (t1[i] != (type) (i-NO))
  1391. X            printf("type: after renum t1[%d] = %t != %d\n",
  1392. X                i, t1[i], i-NO);
  1393. X        t1_free(t1, NB+NO, NE+NO);
  1394. X        
  1395. X
  1396. X        printf("checking type 2 \n");
  1397. X        if (xx_amount() != 0L)
  1398. X            printf("type: amount == %ld", xx_amount());
  1399. X        t2 = t2_alloc(NB, NE, NB, NE);
  1400. X         for (i = NB; i <= NE; i++)
  1401. X             for (j = NB; j <= NE; j++)
  1402. X                 t2[i][j] = (type) (i + j);
  1403. X         for (i = NB; i <= NE; i++)
  1404. X             for (j = NB; j <= NE; j++)
  1405. X                 if (t2[i][j] != (type) (i+j))
  1406. X            printf("type: after allocate t2[%d][%d] = %t != %d\n",
  1407. X                    i, j, t2[i][j], i+j);
  1408. X        t2 = t2_renum(t2, NB, NE, NB, NE, NB+NO, NE+NO, NB+NO, NE+NO);
  1409. X         for (i = NB+NO; i <= NE+NO; i++)
  1410. X             for (j = NB+NO; j <= NE+NO; j++)
  1411. X                 if (t2[i][j] != (type) (i+j-NO-NO))
  1412. X            printf("type: after allocate t2[%d][%d] = %t != %d\n",
  1413. X                    i, j, t2[i][j], i+j-NO-NO);
  1414. X        t2_free(t2, NB+NO, NE+NO, NB+NO, NE+NO);
  1415. X
  1416. X        printf("checking type 3 \n");
  1417. X        if (xx_amount() != 0L)
  1418. X            printf("type: amount == %ld", xx_amount());
  1419. X        t3 = t3_alloc(NB, NE, NB, NE, NB, NE);
  1420. X         for (i = NB; i <= NE; i++)
  1421. X             for (j = NB; j <= NE; j++)
  1422. X                 for (k = NB; k <= NE; k++)
  1423. X                     t3[i][j][k] = (type) (i + j + k);
  1424. X         for (i = NB; i <= NE; i++)
  1425. X             for (j = NB; j <= NE; j++)
  1426. X                 for (k = NB; k <= NE; k++)
  1427. X                     if (t3[i][j][k] != (type) (i+j+k))
  1428. X        printf("type: after allocate t3[%d][%d][%d] = %t != %d\n",
  1429. X                        i, j, k, t3[i][j][k], i+j+k);
  1430. X        t3 = t3_renum(t3, NB, NE, NB, NE, NB, NE, 
  1431. X            NB+NO, NE+NO, NB+NO, NE+NO, NB+NO, NE+NO);
  1432. X         for (i = NB+NO; i <= NE+NO; i++)
  1433. X             for (j = NB+NO; j <= NE+NO; j++)
  1434. X                 for (k = NB+NO; k <= NE+NO; k++)
  1435. X                     if (t3[i][j][k] != (type) (i+j+k-3*NO))
  1436. X        printf("type: after allocate t3[%d][%d][%d] = %t != %d\n",
  1437. X                    i, j, k, t3[i][j][k], i+j+k-3*NO);
  1438. X        t3_free(t3, NB+NO, NE+NO, NB+NO, NE+NO, NB+NO, NE+NO);
  1439. X    }
  1440. X
  1441. END_OF_FILE
  1442. if test 2199 -ne `wc -c <'txtest.c'`; then
  1443.     echo shar: \"'txtest.c'\" unpacked with wrong size!
  1444. fi
  1445. # end of 'txtest.c'
  1446. fi
  1447. if test -f 'xx.sh' -a "${1}" != "-c" ; then 
  1448.   echo shar: Will not clobber existing file \"'xx.sh'\"
  1449. else
  1450. echo shar: Extracting \"'xx.sh'\" \(85 characters\)
  1451. sed "s/^X//" >'xx.sh' <<'END_OF_FILE'
  1452. X:
  1453. sed -e s/type/$1/g -e s/t1/$2"1"/g -e s/t2/$2"2"/g -e s/t3/$2"3"/g $3 >> $4
  1454. exit 0
  1455. END_OF_FILE
  1456. if test 85 -ne `wc -c <'xx.sh'`; then
  1457.     echo shar: \"'xx.sh'\" unpacked with wrong size!
  1458. fi
  1459. chmod +x 'xx.sh'
  1460. # end of 'xx.sh'
  1461. fi
  1462. if test -f 'xxalloc.man' -a "${1}" != "-c" ; then 
  1463.   echo shar: Will not clobber existing file \"'xxalloc.man'\"
  1464. else
  1465. echo shar: Extracting \"'xxalloc.man'\" \(8963 characters\)
  1466. sed "s/^X//" >'xxalloc.man' <<'END_OF_FILE'
  1467. X.TH XXALLOC 3 local
  1468. X.SH NAME
  1469. xxalloc \- family of routines for multi\-dimensional dynamic array allocation,
  1470. initialization, printing, renumbering, and freeing
  1471. X.SH SYNOPSIS
  1472. X.sp
  1473. X.B #include <xxalloc.h>
  1474. X.br
  1475. X.B cc
  1476. X[flags] files
  1477. X.B -lxxalloc [-lxxerror]
  1478. X[libraries]
  1479. X.sp
  1480. X.B
  1481. Base Routines
  1482. X.sp
  1483. void xx_error(s)
  1484. char *s;
  1485. X.br
  1486. char *xx_alloc(n)
  1487. unsigned n;
  1488. X.br
  1489. void xx_free(p, n)
  1490. char *p;
  1491. unsigned n;
  1492. X.br
  1493. long xx_amount()
  1494. X.sp
  1495. X.B
  1496. Prefixes and Arguments
  1497. X.sp
  1498. X{type} \- char \- short \- long \- int \- float \- double
  1499. X.br
  1500. X{*} \- * \- ** \- *** for 1 \- 2 \- 3 dimensions
  1501. X.br
  1502. X{t} \- c \- s \- l \- i \- f \- d
  1503. X.br
  1504. X{d} \- 1 \- 2 \- 3
  1505. X.br
  1506. X{args} \- ib,ie \- ib,ie,jb,je \- ib,ie,jb,je,kb,ke
  1507. X.br
  1508. X.sp
  1509. X.B
  1510. XFunctions for Simple Types
  1511. X.sp
  1512. X{type} {*}{t}{d}_alloc({args})
  1513. X.br
  1514. int {args};
  1515. X.sp
  1516. void {t}{d}_init(m, {args}, ini)
  1517. X.br
  1518. X{type} {*}m;
  1519. X.br
  1520. int {args};
  1521. X.br
  1522. X{type} ini;
  1523. X.sp
  1524. void {t}{d}_prnt(fp, fmt, m, {args})
  1525. X.br
  1526. XFILE *fp;
  1527. X.br
  1528. char *fmt;
  1529. X.br
  1530. X{type} {*}m;
  1531. X.br
  1532. int {args};
  1533. X.sp
  1534. X{type} {*}{t}{d}_renum(m, {args}, {args})
  1535. X.br
  1536. X{type} {*}m;
  1537. X.br
  1538. int {args}, {args};
  1539. X.sp
  1540. void {t}{d}_free(m, {args})
  1541. X.br
  1542. X{type} {*}m;
  1543. X.br
  1544. int {args};
  1545. X.sp
  1546. X.bp
  1547. X.B
  1548. XFunctions for Structures
  1549. X.sp
  1550. char {*}n{d}_alloc({args}, n)
  1551. X.br
  1552. int {args}, n;
  1553. X.sp
  1554. void n{d}_init(m, {args}, n, nini)
  1555. X.br
  1556. char {*}m;
  1557. X.br
  1558. int {args}, n;
  1559. X.br
  1560. void (*nini)();
  1561. X.sp
  1562. void n{d}_prnt(fp, nprn, m, {args}, n)
  1563. X.br
  1564. XFILE *fp;
  1565. X.br
  1566. void (*nprn)();
  1567. X.br
  1568. char {*}m;
  1569. X.br
  1570. int {args}, n;
  1571. X.sp
  1572. char {*}n{d}_renum(m, {args}, {args}, n)
  1573. X.br
  1574. char {*}m;
  1575. X.br
  1576. int {args}, {args}, n;
  1577. X.sp
  1578. void n{d}_free(m, {args}, n)
  1579. X.br
  1580. char {*}m;
  1581. X.br
  1582. int {args}, n;
  1583. X.sp
  1584. X.SH DESCRIPTION
  1585. X.PP 
  1586. xxalloc is a family of routines for dynamic array manipulation in one,
  1587. two and three dimensions.  Routines are included for allocation,
  1588. initialization, printing, renumbering, and freeing both arrays of
  1589. structures and arrays of simple types.  Since the "edge-vector" approach
  1590. is used for two and three dimensional arrays, this set of routines
  1591. allows for the development of reusable subroutine libraries without
  1592. regard to some "maximum" dimension.  Both positive and negative indices
  1593. are allowed.  In this document "array of" is often used where "pointer
  1594. to" would be more correct. 
  1595. X.PP
  1596. X.B
  1597. Base Routines
  1598. X.IP "xx_error"
  1599. The required error handling routine. The default routine exits
  1600. when called, but it may be replaced by a user's routine of the same name.
  1601. The default routine may be linked in by
  1602. X.IP
  1603. X.B cc
  1604. X[flags] files
  1605. X.B \-lxxalloc \-lxxerror
  1606. X[libraries]
  1607. X.sp
  1608. The default routine is simply
  1609. X.sp
  1610. X#include <stdio.h>
  1611. X.br
  1612. void xx_error(s)
  1613. X.br
  1614. char *s;
  1615. X.br
  1616. X{
  1617. X.br
  1618. X    fprintf(stderr, s);
  1619. X.br
  1620. X    exit(2);
  1621. X.br
  1622. X    return;
  1623. X.br
  1624. X}
  1625. X.IP "xx_alloc"
  1626. Allocates memory and checks for error return.  Similar to malloc().
  1627. Returns a NULL pointer if there is no available memory or another error occurs.
  1628. X.IP "xx_free"
  1629. XFree memory allocated with xx_alloc(). Similar to free() but take an extra
  1630. argument for the amount of memory.
  1631. X.IP "xx_amount"
  1632. Returns the amount of memory currently allocated with this package.
  1633. X.PP
  1634. X.B
  1635. The suffix on the function name indicates its function.
  1636. X.B
  1637. The five function types are
  1638. X.IP "_alloc"
  1639. Allocate memory.  Returns an appropriate NULL pointer if there is no
  1640. available memory or another error occurs. 
  1641. X.IP "_init"
  1642. Initialize.
  1643. X.IP "_prnt"
  1644. Print.
  1645. X.IP "_renum"
  1646. Renumber the array indices.
  1647. X.IP "_free"
  1648. XFree the allocated memory.
  1649. X.PP
  1650. X.B
  1651. The prefix on the function name indicates its type. They are
  1652. X.PP
  1653. X.IP "{type}"
  1654. The data type the function manipulates.
  1655. X.IP
  1656. char \- array of structure
  1657. X.br
  1658. char \- array of char
  1659. X.br
  1660. short \- array of short
  1661. X.br
  1662. long \- array of long
  1663. X.br
  1664. int \- array of int
  1665. X.br
  1666. float \- array of float
  1667. X.br
  1668. double \- array of double
  1669. X.PP
  1670. X.IP "{*}"
  1671. Number of dimensions
  1672. X.IP
  1673. X* \- 1 dimension \- pointer to 
  1674. X.br
  1675. X** \- 2 dimensions \- pointer to pointer to
  1676. X.br
  1677. X*** \- 3 dimensions \- pointer to pointer to pointer to
  1678. X.PP
  1679. X.IP "{t}"
  1680. The type that the function manipulates.
  1681. X.IP
  1682. n \- array of structure
  1683. X.br
  1684. c \- array of char
  1685. X.br
  1686. s \- array of short
  1687. X.br
  1688. l \- array of long
  1689. X.br
  1690. i \- array of int
  1691. X.br
  1692. f \- array of float
  1693. X.br
  1694. d \- array of double
  1695. X.PP
  1696. X.IP "{d}"
  1697. The dimension of the array to be manipulated. 
  1698. X.IP
  1699. X1 \- one dimension
  1700. X.br
  1701. X2 \- two dimensions
  1702. X.br
  1703. X3 \- three dimensions
  1704. X.PP
  1705. X.B
  1706. Arguments common to both functions that operate on simple types and structures.
  1707. X.PP
  1708. X.IP "{args}"
  1709. Integer arguments specifying the beginning and ending indices of each
  1710. dimension of the array.  For example the length of an array with
  1711. ib = \-2 and ie = 5 would be ((5 \- (-2)) + 1).
  1712. X.IP 
  1713. ib, ie \- row indices
  1714. X.br
  1715. ib, ie, jb, je \- row and column indices
  1716. X.br
  1717. ib, ie, jb, je, kb, ke \- row, column, and third dimension indices
  1718. X.PP
  1719. X.IP "fp"
  1720. XFILE pointer for the printing functions' output.
  1721. X.PP
  1722. X.B
  1723. Arguments to functions that operate on simple types.
  1724. X.PP
  1725. X.IP "ini"
  1726. Value to initialize the array to.  Must be of {type}.
  1727. X.PP
  1728. X.IP "fmt"
  1729. Character string to be passed as an argument to fprintf.  It should
  1730. contain the conversion specification for a single argument of {type}. 
  1731. X.PP
  1732. X.B
  1733. Arguments to functions that operate on structures.
  1734. X.PP
  1735. X.IP "n"
  1736. sizeof the structure.
  1737. X.PP
  1738. X.IP "nini"
  1739. Pointer to a function used to initialize the structure.  The function
  1740. receives a pointer to the structure as the only argument as shown.
  1741. X.sp
  1742. void initialize_some_structure(some_struct)
  1743. X.br
  1744. struct *some_struct;
  1745. X.PP
  1746. X.IP "nprn"
  1747. Pointer to a function used to print the structure.  The function
  1748. receives a FILE pointer and a pointer to the structure as arguments as shown.
  1749. An example is
  1750. given in the examples section.
  1751. X.sp
  1752. void print_some_structure(fp, some_struct)
  1753. X.br
  1754. XFILE *fp;
  1755. X.br
  1756. struct *some_struct;
  1757. X.SH EXAMPLES
  1758. X.sp
  1759. X.B
  1760. XExample1 \- Operations on a two dimensional array of doubles
  1761. X.sp
  1762. X/* example1.c */
  1763. X.sp
  1764. X#include <stdio.h>
  1765. X.br
  1766. X#include <xxalloc.h>
  1767. X.sp
  1768. void mtxtsp(a, ib, ie, jb, je, b)
  1769. X.br
  1770. double **a, **b;
  1771. X.br
  1772. int ib, ie, jb, je;
  1773. X.br
  1774. X{
  1775. X.br
  1776. X    int i, j;
  1777. X.br
  1778. X    double tmp;
  1779. X.br
  1780. X    
  1781. X.br
  1782. X    for (i = ib; i <= ie; i++)
  1783. X.br
  1784. X         for (j = i; j <= je; j++)
  1785. X.br
  1786. X        {
  1787. X.br
  1788. X            tmp = a[i][j];
  1789. X.br
  1790. X            b[i][j] = a[j][i];
  1791. X.br
  1792. X            b[j][i] = tmp;
  1793. X.br
  1794. X        }
  1795. X.br
  1796. X    return;
  1797. X.br
  1798. X}
  1799. X.sp
  1800. main()
  1801. X.br
  1802. X{
  1803. X.br
  1804. X    double **a;
  1805. X.br
  1806. X    int i, j;
  1807. X.br
  1808. X    
  1809. X.br
  1810. X/* allocate a two dimensional array of doubles */
  1811. X.sp
  1812. X    a = d2_alloc(0, 9, 0, 9);
  1813. X.sp
  1814. X/* initialize the array to 1.0 and print */
  1815. X.sp
  1816. X    d2_init(a, 0, 9, 0, 9, 1.0);
  1817. X.br
  1818. X    printf("\\ninitialized to 1\\n");
  1819. X.br
  1820. X    d2_prnt(stdout, "%5.0f ", a, 0, 9, 0, 9);
  1821. X.sp
  1822. X/* set the array equal to the 2*i + j and print */
  1823. X.sp
  1824. X    for (i = 0; i < 10; i++)
  1825. X.br
  1826. X        for (j = 0; j < 10; j++)
  1827. X.br
  1828. X            a[i][j] = (double) (2*i + j);
  1829. X.br
  1830. X    printf("\\n2*i + j\\n");
  1831. X.br
  1832. X    d2_prnt(stdout, "%5.0f ", a, 0, 9, 0, 9);
  1833. X.sp
  1834. X/* take the transpose and print*/
  1835. X.sp
  1836. X    mtxtsp(a, 0, 9, 0, 9, a);
  1837. X.br
  1838. X    printf("\\ntransposed\\n");
  1839. X.br
  1840. X    d2_prnt(stdout, "%5.0f ", a, 0, 9, 0, 9);
  1841. X.sp
  1842. X/* renumber the indices a la FORTRAN and print */
  1843. X.br
  1844. X/* the new indices must be used from now on */
  1845. X.sp
  1846. X    a = d2_renum(a, 0, 9, 0, 9, 1, 10, 1, 10);
  1847. X.br
  1848. X    printf("\\nrenumbered\\n");
  1849. X.br
  1850. X    d2_prnt(stdout, "%5.0f ", a, 1, 10, 1, 10);
  1851. X.sp
  1852. X/* renumber the indices a la C and print */
  1853. X.br
  1854. X/* the new indices must be used from now on */
  1855. X.sp
  1856. X    a = d2_renum(a, 1, 10, 1, 10, 0, 9, 0, 9);
  1857. X.br
  1858. X    printf("\\nrenumbered again\\n");
  1859. X.br
  1860. X    d2_prnt(stdout, "%5.0f ", a, 0, 9, 0, 9);
  1861. X.sp
  1862. X/* free the allocated memory */
  1863. X.sp
  1864. X    d2_free(a, 0, 9, 0, 9);
  1865. X.br
  1866. X    exit(0);
  1867. X.br
  1868. X}        
  1869. X.sp
  1870. X.B
  1871. XExample 2 \- Operations on an array of structures
  1872. X.sp
  1873. X/* example2.c */
  1874. X.sp
  1875. X#include <stdio.h>
  1876. X.br
  1877. X#include <xxalloc.h>
  1878. X.sp
  1879. typedef struct
  1880. X.br
  1881. X{
  1882. X.br
  1883. X    double dnum;
  1884. X.br
  1885. X    int inum;
  1886. X.br
  1887. X} NUM;
  1888. X.sp
  1889. X/* structure initialization function */
  1890. X.br
  1891. X/* passed as an argument to {d}n_init() */
  1892. X.br
  1893. void num_init(num)
  1894. X.br
  1895. NUM *num;
  1896. X.br
  1897. X{
  1898. X.br
  1899. X    num->dnum = 1.0;
  1900. X.br
  1901. X    num->inum = 1;
  1902. X.br
  1903. X    return;
  1904. X.br
  1905. X}
  1906. X.sp
  1907. X/* structure printing function */
  1908. X.br
  1909. X/* passed as an argument to {d}n_prnt() */
  1910. X.br
  1911. void num_prnt(fp, num)
  1912. X.br
  1913. XFILE *fp;
  1914. X.br
  1915. NUM *num;
  1916. X.br
  1917. X{
  1918. X.br
  1919. X    fprintf(fp, "%5.1f %3d ", num->dnum, num->inum);
  1920. X.br
  1921. X    return;
  1922. X.br
  1923. X}
  1924. X.sp
  1925. main()
  1926. X.br
  1927. X{
  1928. X.br
  1929. X    int i;
  1930. X.br
  1931. X    NUM *num;
  1932. X.br
  1933. X    
  1934. X.br
  1935. X/* allocate a one dimensional array of NUM */
  1936. X.sp
  1937. X    num = (NUM *) n1_alloc(0, 4, sizeof(NUM));
  1938. X.sp
  1939. X/* initialize the array to 1.0 and print */
  1940. X.sp
  1941. X    n1_init(num, 0, 4, sizeof(NUM), num_init);
  1942. X.br
  1943. X    printf("\\ninitialized to 1\\n");
  1944. X.br
  1945. X    n1_prnt(stdout, num_prnt, num, 0, 4, sizeof(NUM));
  1946. X.sp
  1947. X/* set the array equal to the i and print */
  1948. X.sp
  1949. X    for (i = 0; i <= 4; i++)
  1950. X.br
  1951. X    {
  1952. X.br
  1953. X        num[i].dnum = (double) i;
  1954. X.br
  1955. X        num[i].inum = i;
  1956. X.br
  1957. X    }
  1958. X.br
  1959. X    printf("\\nset to i\\n");
  1960. X.br
  1961. X    n1_prnt(stdout, num_prnt, num, 0, 4, sizeof(NUM));
  1962. X.sp
  1963. X/* renumber the indices a la FORTRAN and print */
  1964. X.br
  1965. X/* the new indices must be used from now on */
  1966. X.sp
  1967. X    num = (NUM *) n1_renum(num, 0, 4, 1, 5, sizeof(NUM));
  1968. X.br
  1969. X    printf("\\nindices renumbered\\n");
  1970. X.br
  1971. X    n1_prnt(stdout, num_prnt, num, 1, 5, sizeof(NUM));
  1972. X.br
  1973. X    printf("\\n");
  1974. X.sp
  1975. X/* free the allocated memory */
  1976. X.sp
  1977. X    n1_free(num, 1, 5, sizeof(NUM));
  1978. X.br
  1979. X    exit(0);
  1980. X.br
  1981. X}
  1982. X.SH FILES
  1983. X.PP
  1984. X/lib/xxalloc.a
  1985. X.br
  1986. X/lib/xxerror.a
  1987. X.SH BUGS
  1988. X.PP
  1989. There is only minimal error checking and no error checking at all
  1990. between function calls.
  1991. X.SH AUTHOR
  1992. X.PP
  1993. Harold G. Walters
  1994. X
  1995. END_OF_FILE
  1996. if test 8963 -ne `wc -c <'xxalloc.man'`; then
  1997.     echo shar: \"'xxalloc.man'\" unpacked with wrong size!
  1998. fi
  1999. # end of 'xxalloc.man'
  2000. fi
  2001. if test -f 'xxerror.c' -a "${1}" != "-c" ; then 
  2002.   echo shar: Will not clobber existing file \"'xxerror.c'\"
  2003. else
  2004. echo shar: Extracting \"'xxerror.c'\" \(107 characters\)
  2005. sed "s/^X//" >'xxerror.c' <<'END_OF_FILE'
  2006. X/* xxerror.c */
  2007. X#include <stdio.h>
  2008. void xx_error(s)
  2009. char *s;
  2010. X{
  2011. X    fprintf(stderr, s);
  2012. X    exit(2);
  2013. X    return;
  2014. X}
  2015. X
  2016. X
  2017. END_OF_FILE
  2018. if test 107 -ne `wc -c <'xxerror.c'`; then
  2019.     echo shar: \"'xxerror.c'\" unpacked with wrong size!
  2020. fi
  2021. # end of 'xxerror.c'
  2022. fi
  2023. if test -f 'xxh.sh' -a "${1}" != "-c" ; then 
  2024.   echo shar: Will not clobber existing file \"'xxh.sh'\"
  2025. else
  2026. echo shar: Extracting \"'xxh.sh'\" \(85 characters\)
  2027. sed "s/^X//" >'xxh.sh' <<'END_OF_FILE'
  2028. X:
  2029. sed -e s/type/$1/g -e s/t1/$2"1"/g -e s/t2/$2"2"/g -e s/t3/$2"3"/g $3 >> $4
  2030. exit 0
  2031. END_OF_FILE
  2032. if test 85 -ne `wc -c <'xxh.sh'`; then
  2033.     echo shar: \"'xxh.sh'\" unpacked with wrong size!
  2034. fi
  2035. chmod +x 'xxh.sh'
  2036. # end of 'xxh.sh'
  2037. fi
  2038. if test -f 'xxtest.sh' -a "${1}" != "-c" ; then 
  2039.   echo shar: Will not clobber existing file \"'xxtest.sh'\"
  2040. else
  2041. echo shar: Extracting \"'xxtest.sh'\" \(101 characters\)
  2042. sed "s/^X//" >'xxtest.sh' <<'END_OF_FILE'
  2043. X:
  2044. sed -e s/type/$1/g -e s/t1/$2"1"/g -e s/t2/$2"2"/g -e s/t3/$2"3"/g -e s/\%t/\%$3/g $4 >> $5
  2045. exit 0
  2046. END_OF_FILE
  2047. if test 101 -ne `wc -c <'xxtest.sh'`; then
  2048.     echo shar: \"'xxtest.sh'\" unpacked with wrong size!
  2049. fi
  2050. chmod +x 'xxtest.sh'
  2051. # end of 'xxtest.sh'
  2052. fi
  2053. echo shar: End of archive 1 \(of 1\).
  2054. cp /dev/null ark1isdone
  2055. MISSING=""
  2056. for I in 1 ; do
  2057.     if test ! -f ark${I}isdone ; then
  2058.     MISSING="${MISSING} ${I}"
  2059.     fi
  2060. done
  2061. if test "${MISSING}" = "" ; then
  2062.     echo You have the archive.
  2063.     rm -f ark[1-9]isdone
  2064. else
  2065.     echo You still need to unpack the following archives:
  2066.     echo "        " ${MISSING}
  2067. fi
  2068. ##  End of shell archive.
  2069. exit 0
  2070.  
  2071.  
  2072.